// 
// SoapTrace.Net - A soap message monitoring utility. 
// 
// Copyright (C) 2004-2007 Matthew Ward
// 
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
// 
// Matthew Ward (mrward@users.sourceforge.net)
// 


using SoapTrace.Core;
using SoapTrace.Core.Diagnostics;
using SoapTrace.Core.Formatters;
using SoapTrace.Tests.Config;
using System;
using System.IO;
using NUnit.Framework;

namespace SoapTrace.Tests
{
	/// <summary>
	/// Tests the <see cref="SoapTraceConfiguration"/> class.
	/// </summary>
	[ TestFixture ]
	public class ConfigTestFixture
	{
		/// <summary>
		/// Loads a simple config.
		/// </summary>
		[ Test ]
		public void SimpleConfigLoad( )
		{			
			string Xml = GetConfigXml( );
			
			StringReader Reader = new StringReader( Xml );
			
			SoapTraceConfiguration Config = SoapTraceConfiguration.Load( Reader );
			
			// Test general config.
			Assert.IsTrue( Config.DebugMessages, "Invalid debug messages setting." );
			Assert.AreEqual( LogLevel.Debug, Config.DebugLogLevel, "Invalid debug log level." );
			Assert.IsFalse( Config.DebugLogBytesAsString, "Invalid log bytes as string." );
			Assert.AreEqual( 99, Config.DebugMessagesCount, "Invalid max num log entries." );
			
			// Test the formatter entries.
			Assert.AreEqual( 1, Config.MessageFormatterEntries.Count, "Should only be 1 formatter." );
			
			MessageFormatterEntry Entry = Config.MessageFormatterEntries[ 0 ];
			
			Assert.AreEqual( "SoapTrace.Core.Formatters.SoapMessageFormatter, SoapTrace.Core",
			                Entry.FullTypeName,
			                "Full type name is incorrect." );
			
			Assert.AreEqual( "SoapTrace.Core", Entry.AssemblyName, "Assembly name is wrong." );
			Assert.AreEqual( "SoapTrace.Core.Formatters.SoapMessageFormatter", Entry.TypeName, "Type name is wrong." );
			
		}
		
		/// <summary>
		/// Gets the config xml under test.
		/// </summary>
		/// <returns>An xml config string.</returns>
		private string GetConfigXml( )
		{
			return "<soaptrace.config>\r\n" +
				"\t<!-- Debug messages -->\r\n" +
				"\t<!-- Message formatters -->\r\n" +
				"\t<messageFormatters>\r\n" +
				"\t\t<messageFormatter type=\"SoapTrace.Core.Formatters.SoapMessageFormatter, SoapTrace.Core\"/>\r\n" +
				"\t</messageFormatters>\r\n" +
				"\r\n" +
				"\t<debugMessages>true</debugMessages>\r\n" +
				"\t<debugMessagesCount>99</debugMessagesCount>\r\n" +
				"\t<debugLogBytesAsString>false</debugLogBytesAsString>\r\n" +
				"\t<debugLogLevel>Debug</debugLogLevel>\r\n" +
				"</soaptrace.config> ";
		}
	}
}
